using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using ucApi;
public class HL_Admin_UserLogin : Shop, IRequiresSessionState
{
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!this.Page.IsPostBack)
		{
			UserBll userBll = new UserBll(this.conn);
			int num = Fetch.Get("UserID").ToInt32(new int[0]);
			string text = Fetch.Get("login1");
			string text2 = Fetch.Get("login2");
			bool flag = true;
			if (text == "" || text2 == "")
			{
				flag = false;
				this.WriteErrMsg2("", "Please log in from management page!", "");
			}
			if (flag)
			{
				int num2 = 0;
				try
				{
					num2 = text.Decrypt().ToInt32(new int[0]);
				}
				catch
				{
					flag = false;
					this.WriteErrMsg2("", "Please log in from management page!", "");
				}
				if (num2 != num)
				{
					flag = false;
					this.WriteErrMsg2("", "UserID Error!", "");
				}
			}
			if (flag)
			{
				TimeSpan timeSpan = TimeSpan.Zero;
				try
				{
					timeSpan = DateTime.Now - text2.Decrypt().ToDateTime(new DateTime[0]);
				}
				catch (Exception ex)
				{
					flag = false;
					this.WriteErrMsg2("", "Please log in from management page!" + ex.ToString(), "");
				}
				if (timeSpan.TotalMinutes > 1.0)
				{
					flag = false;
					this.WriteErrMsg2("", "Login link has expired!", "");
				}
			}
			if (flag)
			{
				DataTable userByUserID = userBll.GetUserByUserID(num);
				if (userByUserID.Rows.Count == 0)
				{
					flag = false;
					this.WriteErrMsg2("", "The user information not found!", "");
				}
				DataRow dataRow = userByUserID.Rows[0];
				base.user.UserName = dataRow["UserName"].IsNull(new object[0]);
				base.user.Password = dataRow["Password"].IsNull(new object[0]);
				base.user.UserLogin();
				AppSetings appSetings = new AppSetings();
				if (appSetings.GetConfig("UC_ONorOFF") == "ON")
				{
					string s = Func.uc_user_synlogin(base.Request["UserID"].ToInt32(new int[0]));
					base.Response.Write(s);
				}
				base.user.UserID = dataRow["UserID"].ToInt32(new int[0]);
				base.user.GroupID = dataRow["GroupID"].ToInt32(new int[0]);
				base.user.Balance = dataRow["Balance"].ToInt32(new int[0]);
				base.user.UserEmail = dataRow["Email"].IsNull(new object[0]);
				base.user.UserEP = dataRow["UserEP"].ToInt32(new int[0]);
				userByUserID.Dispose();
			}
			if (flag)
			{
				try
				{
					base.Response.Redirect("../Member/MyShop.aspx", true);
				}
				catch
				{
					base.Response.Redirect("../Member/MyShop.aspx", true);
				}
			}
		}
	}
}
